package org.example.springboot;


import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Controller
//@RestController
@RequestMapping("/response")
public class ResponseController {
    @RequestMapping("/r1")
    public String r1() {
        return "/index.html";
    }

    @ResponseBody
    @RequestMapping("/r2")
    public String r2() {
        return "hello";
    }

    @ResponseBody
    @RequestMapping("/r3")
    public String r3() {
        return "<h1>返回HTML片段</h1>";
    }

    @ResponseBody
    @RequestMapping("/r4")
    public Param r4() {
        Param param = new Param();
        param.setAge(18);
        param.setName("张三");
        param.setOther("111");
        return param;
    }

    @ResponseBody
    @RequestMapping("/r5")
    public Map<String,String> r5() {
        Map<String,String> map = new HashMap<>();
        map.put("k1","v1");
        map.put("k2","v2");
        return map;
    }

    @RequestMapping("/r6")
    public String r6() {
        return "/a.js";
    }

    @RequestMapping("/r7")
    public String r7() {
        return "/b.css";
    }

    @ResponseBody
    @RequestMapping("/r8")
    public String r8(HttpServletResponse response) {
        response.setStatus(404);
        return "设置状态码成功";
    }

    @ResponseBody
    @RequestMapping(value = "/r9",produces = "application/json; charset = utf-16")
    public String r9() {
        return "123";
    }

    @ResponseBody
    @RequestMapping(value = "/r10")
    public String r10(HttpServletResponse response) {
        response.setHeader("HeaderKey","HeaderValue");
        return "设置Header成功";
    }
}
